package com.imageim.yimirror.common.ui;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import org.byteam.superadapter.OnItemClickListener;
import org.byteam.superadapter.OnItemLongClickListener;
import org.byteam.superadapter.SuperAdapter;
import org.byteam.superadapter.animation.BaseAnimation;

/**
 * 用于UI构建和初始化等
 * Created by Bruce.Zhou on 2018/11/22 18:01.
 * Email: 907160968@qq.com
 */
public class SuperUIUtil {

    public static class RecycleViewManager<T> {
        private RecyclerView recyclerView;
        private Context context;
        private SuperAdapter<T> adapter;

        public static final int VERTICAL = 1;
        public static final int HORIZONTAL = 2;

        public RecycleViewManager(Context context, RecyclerView recyclerView, SuperAdapter adapter) {
            this.recyclerView = recyclerView;
            this.context = context;
            this.adapter = adapter;
            this.recyclerView.setAdapter(adapter);
        }

        public RecycleViewManager orientation(int orientation) {
            LinearLayoutManager llm = new LinearLayoutManager(context);
            llm.setOrientation(orientation == 1 ? LinearLayoutManager.VERTICAL : LinearLayoutManager.HORIZONTAL);
            recyclerView.setLayoutManager(llm);
            return this;
        }

        public RecycleViewManager onItemClick(OnItemClickListener onItemClickListener) {
            if (onItemClickListener == null) return this;
            adapter.setOnItemClickListener(onItemClickListener);
            return this;
        }

        public RecycleViewManager onItemLongClick(OnItemLongClickListener onItemLongClickListener) {
            if (onItemLongClickListener == null) return this;
            adapter.setOnItemLongClickListener(onItemLongClickListener);
            return this;
        }

        public RecycleViewManager anim(BaseAnimation animation) {
            adapter.enableLoadAnimation(300, animation);
            return this;
        }

        public RecycleViewManager addItemDecoration(RecyclerView.ItemDecoration itemDecoration) {
            recyclerView.addItemDecoration(itemDecoration);
            return this;
        }
    }

    public static RecycleViewManager initRecylerView(Context context, RecyclerView recyclerView, SuperAdapter adapter) {
        RecycleViewManager rvm = new RecycleViewManager(context, recyclerView, adapter);
        return rvm;
    }
}
